package com.kma.ncpractice2013.servlets;

import com.kma.ncpractice2013.dao.LocationDAO;
import com.kma.ncpractice2013.dao.OrderDAO;
import com.kma.ncpractice2013.dao.UserDAO;
import com.kma.ncpractice2013.model.Location;
import com.kma.ncpractice2013.model.Order;
import com.kma.ncpractice2013.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * User: Viktor
 * Date: 10/30/13
 */

public class OrderHistoryServlet extends HttpServlet  //DO NOT USE
{
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{



	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		//PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=UTF-8");
		HttpSession session = request.getSession(false);
		UserDAO userDAO = new UserDAO();
		OrderDAO orderDAO = new OrderDAO();
		LocationDAO locationDAO = new LocationDAO();

		User user = userDAO.getByLogin((String) session.getAttribute("username"));
		List<Order> orderList = orderDAO.getByUser(user.getId());
		Location location;
		double bonus_used = 0;
		for (Order order: orderList)
		{
			/*if(order.getPaymentMethod().equals("bonus")) bonus_used+=order.getPrice();
			location = locationDAO.getById(order.getLocationId());
			out.print(location.getName()+"<br/>");
			out.print("Checkin date: "+ order.getCheckInDate() +"<br/>");
			out.print("Checkout date: "+ order.getCheckOutDate() +"<br/>");
			out.print("Nights: "+order.getNights()+"<br/>");
			out.print("Price: "+order.getPrice()+"<br/>");
			out.print("Payment method: " + order.getPaymentMethod()+"<br/><br/>");*/
		}
	}
}
